home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01a.txt / 000070_icon-group-sender _Tue Jun 27 16:55:20 2000.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA21064
  4.     for icon-group-addresses; Tue, 27 Jun 2000 16:55:06 -0700 (MST)
  5. Message-Id: <200006272355.QAA21064@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 27 Jun 2000 13:08:59 -0700 (MST)
  7. From: Gregg Townsend <gmt@baskerville.CS.Arizona.EDU>
  8. To: Steve_Graham@labcorp.com, icon-group@optima.CS.Arizona.EDU
  9. Subject: Re: Permutations/Combinations
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12. Content-Length: 1054
  13.  
  14.     From: "Steve Graham" <Steve_Graham@labcorp.com>
  15.     
  16.     Although I do not know how to utilize Icon's built-in features to generate
  17.     all possible combinations/permutations (which one is it?) where the letters
  18.     appear once and only once, I do believe that, given the generated list, I
  19.     will recognize the valid words.  And I'm sure that Icon can EASILY produce
  20.     the list, whether the algorthim utilizes reversible assignment or not.
  21.     Can someone show me how?
  22.     
  23. The Icon program library contains a nice little permutation generator
  24. (in the procs/strings.icn file):
  25.  
  26.     procedure permute(s)
  27.        local i
  28.        if *s = 0 then return ""
  29.           suspend s[i := 1 to *s] || permute(s[1:i] || s[i+1:0])
  30.     end
  31.  
  32. So to generate all 720 permutations you'd just do this:
  33.  
  34.     procedure main()
  35.        every write(permute("abelmr"))
  36.     end
  37.  
  38.    ---------------------------------------------------------------------------
  39.    Gregg Townsend         Staff Scientist      The University of Arizona
  40.    gmt@cs.arizona.edu     Computer Science     Tucson, Arizona, USA
  41.